﻿using HECore.Tenant.Contract;
using HECore.Tenant.Contract.Models.Emoloyees.Dtos;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using System.ComponentModel.DataAnnotations;
using HECore.Tenant.Contract.Models.Emoloyees.Inputs;
using HECore.Tenant.Repository.Entites;

namespace HECore.Tenant.WebApi.Controllers
{
    /// <summary>
    /// 员工
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class EmployeeController : ControllerBase
    {
        private readonly IEmployeeService _emoloyeeService;
        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="emoloyeeService"></param>
        public EmployeeController(IEmployeeService emoloyeeService)
        {
            _emoloyeeService = emoloyeeService;
        }

        /// <summary>
        /// 获取账号绑定的员工列表
        /// </summary>
        /// <param name="AccountId">账号Id</param>
        /// <returns></returns>
        [HttpGet("lines/by-accountId")]
        public async Task<List<EmployeeDetailsDto>> GetAccountEmoloyees([FromQuery][Required] Guid AccountId)
        {
            return await _emoloyeeService.GetAccountEmoloyees(AccountId);
        }

        /// <summary>
        /// 获取员工权限
        /// </summary>
        /// <param name="EmployeeId">员工Id</param>
        /// <param name="TenantId">租户Id</param>
        /// <returns></returns>
        [HttpGet("permissions")]
        public async Task<EmployeePermissionsDto> GetEmployeePermissions([FromQuery][Required] Guid EmployeeId, [FromQuery][Required] Guid TenantId)
        {
            return await _emoloyeeService.GetEmployeePermissions(EmployeeId, TenantId);
        }

        /// <summary>
        /// 设置员工Token
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("set-token")]
        public async Task SetToken(SetTokenInput input) {
            await _emoloyeeService.SetToken(input);
        }
    }
}
